package cn.chen.server.util;

import java.nio.charset.Charset;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;

public class SendMsg {
	public static boolean sendMsg(String port, String msg) {
		if (!ChannelMap.isExistence(port)) {
			return false;
		}
		ChannelHandlerContext channelHandlerContext = ChannelMap.getChannelByName(port);
		if (channelHandlerContext.channel().isActive()) {
			ByteBuf buff = channelHandlerContext.alloc().buffer(64); // (2)
			buff.writeBytes(msg.getBytes(Charset.forName("gb2312")));
			channelHandlerContext.writeAndFlush(buff);
		} else {
			return false;// 不在线
		}
		return true;
	}
}
